import { request } from "@umijs/max";;
import { UMS_REQUEST_PREFIX } from "@/utils/config";
import { deptTypes, functionTypes, pager, roleTypes, userTypes } from "@/constants/types";

const PREFIX = "/permission";
const SSO_PREFIX = "/sso";

// 角色管理
/**
 * 获取角色列表
 * @returns 
 */
export async function fetchRoleList(params: {pageNum: number, pageSize: number}) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/list`, {
    method: 'POST',
    dataField: 'data',
    data: params
  });
}
/**
 * 获取角色下拉列表
 * @returns 
 */
export async function fetchRoleListOptions() {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/options`, {
    method: 'POST',
    dataField: 'data'
  });
}
/**
 * 获取菜单功能树
 * @returns 
 */
export async function fetchRoleFunctionTree(id: string) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/functionTree`, {
    method: 'POST',
    data: {id}
  });
}
/**
 * 新增角色
 * @param params 
 * @returns 
 */
export async function addRole(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 编辑角色
 * @param params 
 * @returns 
 */
export async function updateRole(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除角色
 * @param params 
 * @returns 
 */
export async function deleteRole(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/delete`, {
    method: 'POST',
    data: params
  });
}
/**
 * 角色详情
 * @param params 
 * @returns 
 */
export async function fetchRoleDetail(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/role/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}

// 菜单列表
/**
 * 菜单列表
 * @param params 
 * @returns 
 */
export async function fetchMenuList(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 菜单树
 * @param params 
 * @returns 
 */
export async function fetchMenuTree() {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/tree`, {
    method: 'POST'
  });
}
/**
 * 菜单详情
 * @param params 
 * @returns 
 */
export async function fetchMenuDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 修改菜单
 * @param params 
 * @returns 
 */
export async function addMenu(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 修改菜单
 * @param params 
 * @returns 
 */
export async function updateMenu(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除菜单
 * @param params 
 * @returns 
 */
export async function deleteMenu(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/menu/delete`, {
    method: 'POST',
    data: params
  });
}
/**
 * 功能列表
 * @param params 
 * @returns 
 */
export async function fetchFunctionList(params: roleTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/function/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 功能详情
 * @param params 
 * @returns 
 */
export async function fetchFunctionDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/function/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 新增功能
 * @param params 
 * @returns 
 */
export async function addFunction(params: functionTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/function/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 修改功能
 * @param params 
 * @returns 
 */
export async function updateFunction(params: functionTypes) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/function/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除功能
 * @param params 
 * @returns 
 */
export async function deleteFunction(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${PREFIX}/function/delete`, {
    method: 'POST',
    data: params
  });
}
//用户中心
/**
 * 部门树
 * @returns 
 */
export async function fetchDeptTree() {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/dept/tree`, {
    method: 'POST'
  });
}
/**
 * 新增部门
 * @param params 
 * @returns 
 */
export async function addDept(params: deptTypes) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/dept/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 新增部门
 * @param params 
 * @returns 
 */
export async function updateDept(params: deptTypes) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/dept/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 用户列表
 * @param params 
 * @returns 
 */
export async function fetchInnerUserList(params: pager) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 添加用户
 * @param params 
 * @returns 
 */
export async function addInnerUser(params: userTypes) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 修改用户
 * @param params 
 * @returns 
 */
export async function updateInnerUser(params: userTypes) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 启用用户
 * @param params 
 * @returns 
 */
export async function enableInnerUser(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/enable`, {
    method: 'POST',
    data: params
  });
}
/**
 * 禁用用户
 * @param params 
 * @returns 
 */
export async function disableInnerUser(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/disable`, {
    method: 'POST',
    data: params
  });
}
/**
 * 获取用户详情
 * @param params 
 * @returns 
 */
export async function fetchInnerUserDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 重置密码
 * @param params 
 * @returns 
 */
export async function resetInnerUserPassword(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}${SSO_PREFIX}/innerUser/resetPassword`, {
    method: 'POST',
    data: params
  });
}